package com.qf.shop.system.modules.promote.service.impl;

import com.qf.shop.system.utils.PageUtils;
import com.qf.shop.system.utils.Query;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.qf.shop.system.modules.promote.dao.PromotionDao;
import com.qf.shop.system.modules.promote.entity.PromotionEntity;
import com.qf.shop.system.modules.promote.service.PromotionService;


@Service("promotionService")
public class PromotionServiceImpl extends ServiceImpl<PromotionDao, PromotionEntity> implements PromotionService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<PromotionEntity> page = this.page(
                new Query<PromotionEntity>().getPage(params),
                new QueryWrapper<PromotionEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<PromotionEntity> limit(Integer limit) {

        // 1.查询当前要展示的数据
        List<PromotionEntity> currList = baseMapper.currentDateList(limit);

        // 2.判断当天是否有数据
        if (currList == null && currList.size() == 0) {
            currList = baseMapper.oldDateList(limit);
        }
        return currList;
    }

}